--有备无患
local youbeiwuhuan = fk.CreateSkill {
    name = "mcdh_youbeiwuhuan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

youbeiwuhuan:addEffect('viewas',{
    pattern = "jink",
    card_filter = function(self,player, to_select, selected)
        if #selected == 1 then return false end
        local _c = Fk:getCardById(to_select)
        local c = Fk:cloneCard("jink")
        if _c.trueName ~= "slash" then
            return false
        end
        return (Fk.currentResponsePattern == nil and player:canUse(c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
    end,
    view_as = function(self,player, cards)
        if #cards ~= 1 then
            return nil
        end
        local c = Fk:cloneCard("jink")
        c.skillName = self.name
        c:addSubcard(cards[1])
        return c
    end,
    enabled_at_response = function (self, player, response)
        return not response
    end
})

youbeiwuhuan:addEffect(fk.CardUsing,{
    can_trigger = function (self, event, target, player, data)
        if event == fk.CardUsing then
            return player:hasSkill(self) and target ~= player and data.card.name == "jink"
        end
    end,
    on_cost = function (self, event, target, player, data)
        local card
        local room = player.room
        if event == fk.CardUsing then
            card = room:askForResponse(player, self.name, "jink", "#mcdh_youbeiwuhuan_jink:"..target.id, true)
        end
        if card ~= nil then
            self.cost_data = card
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local card = self.cost_data
        room:responseCard({
            from = player,
            card = card,
        })
        data.tos = {}
    end
})

Fk:loadTranslationTable {
    ["mcdh_youbeiwuhuan"] = "绸缪",
    [":mcdh_youbeiwuhuan"] = "『有备无患』<br>你可以将【杀】当【闪】使用；其他角色使用【闪】时，你可以打出一张【闪】无效之。",
    ["#mcdh_youbeiwuhuan_jink"] = "有备无患：你可以打出一张【闪】，无效 %src 使用的【闪】",
}

return youbeiwuhuan